package com.acheli.rideable.functionLathes;


import com.acheli.registry.network.ACHMessages;
import com.acheli.registry.network.ACHeliPacketType;
import com.acheli.registry.network.ICustomSyncable;
import com.acheli.registry.network.packet.CustomSyncableC2SPacket;
import com.acheli.rideable.factory.ACHeliEntitiesFactory;
import com.acheli.rideable.functionLathes.component.compile.EventToJS;
import com.mojang.blaze3d.vertex.PoseStack;
import net.minecraft.client.renderer.MultiBufferSource;
import net.minecraft.client.renderer.entity.EntityRendererProvider;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.player.Player;
import org.mozilla.javascript.Context;

public class EntityFLProvider<T, FunctionLathe>  {
    protected T cachedEntity;
    private ACHeliEntitiesFactory<T, FunctionLathe> acheliEntitiesFactory;
    protected boolean _shouldRender = false;

    protected FunctionLathe fl;

    public EntityFLProvider(FunctionLathe fl) {
        this.fl = fl;
    }

    public FunctionLathe getFL() {
        return fl;
    }

    public void INIT() {

    }
    public void setFactory(ACHeliEntitiesFactory<T, FunctionLathe> ACHeliEntitiesFactory) {
        this.acheliEntitiesFactory = ACHeliEntitiesFactory;
    }

    public ACHeliEntitiesFactory<T, FunctionLathe> getFactory() {
        return acheliEntitiesFactory;
    }

    public void setEntity(T input) {
        cachedEntity = input;
    }

    public boolean shouldRender() {
        return _shouldRender;
    }

    public void renderDistance(double distance) {
        _shouldRender = distance < 160;
    }

    public void render(EntityRendererProvider.Context context, T entity, float yaw, float partialTick,
                       PoseStack poseStack, MultiBufferSource buffer, int packedLight) {

    }

    public void kill(){
        Context.exit();
    }

    public void runScript(EventToJS event) {}

    public void tick() {

    }

    public void renderTick(PoseStack matrices, float tickDelta) {

    }

    public void onClientTick(){

    }

    public void interact(Player player, InteractionHand hand) {

    }

    public void clientSend(CompoundTag nbt, ACHeliPacketType packetType) {
        if (cachedEntity instanceof Entity entity && cachedEntity instanceof ICustomSyncable) {
            ACHMessages.sendToServer(new CustomSyncableC2SPacket(
                    entity.getId(), entity.getUUID(), nbt, packetType));
        }
    }

    public CompoundTag serverReceiveAndSending(CompoundTag serverOriginNbt, ServerPlayer executingPlayer, ACHeliPacketType packetType) {
        return null;
    }


    public void clientReceive(CompoundTag receivedNbt, boolean fromSelf, ACHeliPacketType packetType) {

    }
}
